package com.gao.controller;

import com.gao.service.FileService;
import com.gao.utils.ResultVo;
import com.gao.vo.Base64Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author gao
 * @date 2023/05/12 21:22:59
 */
@RestController
public class UploadFileController {

    @Autowired
    private FileService fileService;

    @PostMapping("uploadSingleFile")
    public ResultVo uploadSingleFile(MultipartFile file) {
        String url = fileService.uploadFile(file);
        return ResultVo.success("上传文件成功", url);
    }

    @PostMapping("uploadSingleFileWithHashFilename")
    public ResultVo uploadSingleFileWithHashFilename(MultipartFile file, String filename) {
        String url = fileService.uploadSingleFileWithHashFilename(file, filename);
        return ResultVo.success("上传文件成功", url);
    }

    @PostMapping("uploadBase64SingleFile")
    public ResultVo uploadBase64SingleFile(Base64Vo file) {
        String url = fileService.uploadBase64File(file);
        return ResultVo.success("上传文件成功", url);
    }

    @PostMapping("uploadBigFilePiece")
    public ResultVo uploadBigFilePiece(MultipartFile file, String hash, int pieceIndex, int totalPieces, String suffix) {
        String result = fileService.uploadBigFile(file, hash, pieceIndex, totalPieces, suffix);
        return ResultVo.success(result);
    }
}
